//
//  ZFSettingScrollView.swift
//  map
//
//  Created by fyzq on 2024/2/2.
//

import UIKit
import BetterSegmentedControl
class ZFSettingScrollView: UIScrollView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setZFSettingScrollView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setZFSettingScrollView(){
        
        let flyAnimatedView = ZFFlyAnimatedView()
        flyAnimatedView.backgroundColor = R.color.bg()
        flyAnimatedView.addRadius(radius: 6)
//        flyAnimatedView.jk_shadow(with: .color99, offset: CGSize(width: 0, height: 2), opacity: 1, radius: 6)
        addSubview(flyAnimatedView)
        flyAnimatedView.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.width.equalTo(UIDevice.width - 30)
        }
        
    }

    
}



class ZFFlyAnimatedView :ZFBaseView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setZFFlyAnimatedView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setZFFlyAnimatedView(){
        
        let cell = ZFIconCustomCell()
        cell.iconLabel.text = .icon(icon: .ic_earth)
        cell.arrow.isHidden = true
        cell.titleLabel.text = "动画"
        
        let cell1 = ZFContentCustomCell()
        cell1.titleLabel.text = "动画时长"
        cell1.contentLabel.text = "1.5秒"

        
        let cell2 = ZFCustomCell()
        cell2.arrow.isHidden = true
        cell2.titleLabel.text = "动画效果"
        let segments = LabelSegment.segments(withTitles: ["缓入缓出", "缓入","缓出", "平滑","飞行"],normalFont: UIFont.systemFont(ofSize: 11),normalTextColor:R.color.color_66(), selectedFont: UIFont.systemFont(ofSize: 11),selectedTextColor: .white)
        
        let segmentedControl =  BetterSegmentedControl(frame: CGRect.zero, segments:segments,options:
                                                        [.indicatorViewBackgroundColor(R.color.accentColor()!),
                                                         .cornerRadius(15.0),])

        let animatedView = ZFGroupCustomCell(arrangedSubviews: [cell,cell1,cell2,segmentedControl])
        addSubview(animatedView)
        animatedView.snp.makeConstraints { make in
            make.edges.equalToSuperview().inset(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
        }
        
        
        
        
        
//        addSubview(segmentedControl)
//        segmentedControl.snp.makeConstraints { make in
//            make.top.equalTo(detailLabel.snp.bottom).offset(10)
//            make.left.right.equalTo(titleLabel);
//            make.bottom.equalTo(-10)
//        }
//        let times = [8,5,2.5,1.5,0.3];
//        
//        guard let index = times.firstIndex(of: ZFConfigManager.shared.config.duration) else {
//            segmentedControl.setIndex(2)
//            ZFConfigManager.shared.config.duration = times[2]
//            ZFConfigManager.shared.zf_save()
//            return;
//        }
//        segmentedControl.setIndex(index)
//        segmentedControl.rx.controlEvent(.valueChanged).subscribe(on: MainScheduler.instance).subscribe(onNext:{[weak segmentedControl]_ in
//            guard let control = segmentedControl else {
//                return;
//            }
////            print(control.index);
//            
//            ZFConfigManager.shared.config.duration = times[control.index]
//            ZFConfigManager.shared.zf_save()
//       
//        }).disposed(by: dis);
        
        
    }
}
